
# Uganda ------------------------------------------------------------------

# Uganda 1

m1 <- lm(police_satisfactory ~ female + as.factor(tc), data = ug1)

# Uganda 2
m2 <- lm(police_satisfactory ~ female + as.factor(tc_id), data = ug2)

# Uaganda 3
m3 <- lm(police_not_bribe ~ female + as.factor(tc_id), data = ug3)


# Tanzania ----------------------------------------------------------------
# Information on gender is missing for two respondents in the first Tanzania wave
# Hence, these respondents are dropped from this analysis.
m4 <- lm(police_satisfactory ~ female + as.factor(village), data = tan)

# South Africa ------------------------------------------------------------

m5 <- lm(trust_police ~ female + community, data = sa)

# Afrobarometer -----------------------------------------------------------

m6 <- lm(trust_police ~ female + region, data = afro)

m7 <- lm(no_police_corrupt ~ female + region, data = afro)

m8 <- lm(easy_obtain_police_service ~ female + region, data = afro)


# Get HC1 robust standard errors from estimatr package
ses<- starprep(m1,
               m2,
               m3,
               m4,
               m5,
               m6,
               m7,
               m8, stat = "std.error",se_type = "HC1")

pvals<- starprep(m1,
                 m2,
                 m3,
                 m4,
                 m5,
                 m6,
                 m7,
                 m8, stat = "p.value",se_type = "HC1")




sink("04_manuscript/tables/views_police_gender.tex")
stargazer(
  m1,
  m2,
  m3,
  m4,
  m5,
  m6,
  m7,
  m8,
  se = ses,
  p = pvals,
  # type = "text",
  omit.stat = c("rsq","f","ser"), 
  keep = "female",
  column.labels = c("Uganda 1","Uganda 2","Uganda 3","Tanzania 1","South Africa","Afrobar.", "Afrobar.","Afrobar."),
  #column.separate = c(1,1,1,1,1,3),
  #table.layout = "=cd#-t-as=n",
  covariate.labels = "Woman",
  add.lines = list(
    c(
      "Avg. men",
      round(c(with(ug1,mean(police_satisfactory[female == 0],na.rm = TRUE)),
              with(ug2,mean(police_satisfactory[female == 0],na.rm = TRUE)),
              with(ug3,mean(police_not_bribe[female == 0],na.rm = TRUE)),
              with(tan,mean(police_satisfactory[female == 0],na.rm = TRUE)),
              with(sa,mean(trust_police[female == 0],na.rm = TRUE)),
              with(afro,mean(trust_police[female == 0],na.rm = TRUE)),
              with(afro,mean(no_police_corrupt[female == 0],na.rm = TRUE)),
              with(afro,mean(easy_obtain_police_service[female == 0],na.rm = TRUE)))
              ,2)),
    c("Area FE",rep("Yes",8)),
    c("Outcome",c("Satisf.","Satisf.","No Bribe","Satisf.","Trust","Trust","Not Corrupt", "Easy access"))
  ),
  no.space = TRUE,dep.var.caption = "Police Approval",float = F,
  
  dep.var.labels.include = FALSE
)
sink()



rm(m1,
   m2,
   m3,
   m4,
   m5,
   m6,
   m7,
   m8,ses,pvals)

